package de.islanders.persistence;

import javax.persistence.EntityManager;

import de.islanders.unit.player.Player;

public class PlayerDAO {

	private EntityManager entityManager;
	
	public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    protected EntityManager getEntityManager() {
        if (entityManager == null)
            throw new IllegalStateException(
                    "EntityManager has not been set on DAO before usage");
        return entityManager;
    }
    
    public Player findById(Integer id){
    	return entityManager.find(Player.class, id);
    }
    
    public void makePersistent(Player player){
    	entityManager.getTransaction().begin();
    	entityManager.persist(player);
    	entityManager.getTransaction().commit();
    }
}
